package com.agriculture.data_demo.config;

import org.springframework.boot.SpringBootConfiguration;
import org.springframework.context.annotation.Bean;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @author morningbear
 * @date 20.10.8
 */
@SpringBootConfiguration
@EnableSwagger2
public class SwaggerUiConfig {

    public static final String SWAGGER_SCAN_BASE_PACKAGE = "com.agriculture.data_demo.controller.api";

    public static final String VERSION = "0.0.1";

    @Bean("clientAPI")
    public Docket api(){
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("客户端")
                .select()
                .apis(RequestHandlerSelectors.basePackage(SWAGGER_SCAN_BASE_PACKAGE))
                .paths(PathSelectors.any())
                .build()
                .apiInfo(apiInfo());
    }

    /**
     * SwaggerUI文档的基本信息
     *
     */
    private ApiInfo apiInfo(){
        return new ApiInfoBuilder()
                .title("动植物大数据平台")
                .description("现在只有猪和鸡，且缺少种猪和蛋鸡")
                .termsOfServiceUrl("NO terms of service")
                .version(VERSION)
                .license("The Apache License, Version 2.0")
                .licenseUrl("http://www.apache.org/licenses/LICENSE-2.0.html")
                .build();
    }
}
